<?php
@session_start();
include_once 'session_var.php';
if($_SESSION['web']!=true) {
		$_SESSION['languaje'] = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
		//header('Location: http://firstclassapartment.com.ar/'.$_SESSION['languaje'].'/bookupd.php');
		header('Location: //localhost/firstclassapartmentscordoba/'.$_SESSION['languaje'].'/bookupd.php');  
}else {
	include("../lang/{$_SESSION['languaje']}.php");
}

//$code=$_GET['code'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang=<?php echo $_SESSION['languaje'];?>>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content=<?php echo $book_description;?>>
		<meta name="author" content="Pulce Web Solutions - www.pulce.com.ar">
		<!--Para que las páginas se muestren correctamente y el zoom funcione bien en los dispositivos móviles-->
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="keywords" content="<?php echo $index_keywords;?>">

		<title><?php echo $book_title?></title>

		<?php
			include_once('links.php');
			include_once('function.inc.php');
			include_once("analytics.php");
		?>
		<!--<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />-->
		<link href="../css/sunny/jquery-ui-1.10.4.custom.min.css" rel="stylesheet">

		<!--JQUERY-->
		<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
		<!--BOOTSTRAP
		<script src="../js/bootstrap.min.js"></script>-->
		<!--FUNCTIONS-->
		<script src="../js/functions.js"></script>
		<!--JQ-UI-->
		<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
		<!--DATEPICKER LANGUAJE-->
		<?php if ($_SESSION['languaje']<>"en"){?>
		<script src="../js/datapicker-languajes/jquery.ui.datepicker-<?php echo $_SESSION['languaje'];?>.js"></script>
		<?php } ?>
		<!-- BACKSTRECH -->
		<script src="../js/jquery.backstretch.min.js"></script>
		<!-- DROPDOWN -->
		<script src="../js/dropdown.js"></script>
		<!-- TRANSITION -->
		<script src="../js/transition.js"></script>
		<!-- MODAL -->
		<script src="../js/modal.js"></script>

		<script type="text/javascript">
			$(document).ready(function(){

				$( "#inputCode" ).focus();

				$.datepicker.setDefaults({
				  	showOn: "both",
					<?php if($_SESSION['languaje']=='es'){?>
						dateFormat: "dd/mm/yy",
					<?php }else{?>
					  	dateFormat: "mm/dd/yy",
					<?php }?>
					buttonImage: "../img/symbol/calendar-icon-512x512.png",
					defaultDate: "now",
					maxDate: "+1y",
					minDate: "now"
				});
				$("#checkin").datepicker({
		        	onClose: function (selectedDate) {
		            	if (!isEmpty('checkin')){
		            		var dateMin = $('#checkin').datepicker("getDate");
							var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
		            		$("#checkout").datepicker("option", "minDate", rMin);
		            		$("#checkout").datepicker( "show" );}
		            }			
				});
				$("#checkout").datepicker({
				});

				$('#box').on('change',function(e){
					if (isSet('div-msg'))
						$('#div-msg').fadeOut();
				});

				//Cargo combo moneda
				g("../ajax.php?"+a('ArmarComboMoneda')+c('table','T_CURRENCY')+c('id','id_currency')+c('value','concat(chr_value,\' - \',chr_description_<?php echo $_SESSION['languaje'];?>)')+c('name','inputCurrency')+c('puntero','3'), 'SelectCurrency' , '' , 'img-loading',true);
				//Cargo combo pais
				g("../ajax.php?"+a('ArmarComboPais')+c('table','T_COUNTRIES')+c('id','id_country')+c('value','chr_name_<?php echo $_SESSION['languaje'];?>')+c('msgSelect','<?php echo $msg_select;?>')+c('name','inputCountry')+c('tabindex','3'), 'SelectCountry' , '' , 'img-loading',true);
				
				//Codigo telefonico
				$('#SelectCountry').change(function() {
					var id = $("#inputCountry").val();
					g("../ajax.php?"+a('returnDialCode')+c('id',id), 'dialingCode' , '' , 'img-loading',true);
					g("../ajax.php?"+a('returnDialCode')+c('id',id), 'dialingOptCode' , '' , 'img-loading',true);
				});

				//Combo Horario
				g("../ajax.php?"+a('armarComboArrive')+c('msgKnow','<?php echo $msg_know;?>')+c('msgNext','<?php echo $msg_next;?>')+c('name','inputArrive')+c('tabindex','8'), 'SelectArrive' , '' , 'img-loading',true);
				
				//Cambio de moneda
				$('#SelectCurrency').change(function(){
					g('../ajax.php?'+a('calcPrice')+v('checkin')+v('checkout')+v('guests')+v('inputCurrency'),'pricing', 'div-msg' , 'img-loading',true,true);
				});

				//Cambian las variables, cambian los precios
				$('#updPrice').change(function(){
					g('../ajax.php?'+a('calcPrice')+v('checkin')+v('checkout')+v('guests')+v('inputCurrency'),'pricing', 'div-msg' , 'img-loading',true);
				});

				//Buscar codigo
				$('#btn-finbooking').on('click',function(e){
					if ($('#booking-data').is (':visible')){
						$('#booking-data').toggle(300);
					}
					if (isSet('confirmation1'))
						$('#confirmation1').fadeOut();
					if (isSet('confirmation2'))
						$('#confirmation2').fadeOut();
					if (isSet('div-msg'))
						$('#div-msg').fadeOut();
					g("../ajax.php"+a('getBookingData')+v('inputCode'),'result','div-msg','img-loading',true);
				});

				//Disponibilidad
				$('#checkin').on('change',function(e){
					g("../ajax.php?"+a('check_availability')+v('checkin')+v('checkout')+v('guests')+v('code'), '' , 'div-msg' , 'img-loading',true);
				});
				$('#checkout').on('change',function(e){
					g("../ajax.php?"+a('check_availability')+v('checkin')+v('checkout')+v('guests')+v('code'), '' , 'div-msg' , 'img-loading',true);
				});

				//Validar y Guardar archivos
				$('#btn-confirm').on('click',function(e){
					if (isSet('div-msg')){
						finish('div-msg');
						$('#div-msg').fadeOut();
					}
					g("../ajax.php?"+a('check_availability')+v('checkin')+v('checkout')+v('guests')+v('code'), '' , 'div-msg' , 'img-loading',false);
					if (hasMsg('div-msg'))
						return;
					g('../ajax.php?'+a('verifBookingData')+v('inputName')+v('inputLastName')+v('inputCountry')+v('inputEmail')+v('inputConfirmEmail')+v('inputPhone'),'', 'div-msg' , 'img-loading',false);
					if (hasMsg('div-msg'))
						return;
					g("../ajax.php?"+a('updateBooking')+v('checkin')+v('checkout')+v('guests')+v('inputName')+v('inputLastName')+v('inputCountry')+v('inputEmail')+v('inputConfirmEmail')+v('inputPhone')+v('inputOptPhone')+'&arrive='+$("#inputArrive option:selected").html()+v('inputArrive')+v('inputRequest')+v('inputCurrency')+v('code'), 'result' , 'div-msg' , 'img-loading',true);
				});

			});
		</script>
				
	<body>
		<div id="menu_bar">
				<?php include_once('menu_bar.php');?>
			</div>
		<div class="container">
			
			<div id="backstretch">
				<script>
					$.backstretch([
					"../img/bkbook.jpg"
					],{duration: 5000,fade:750});
				</script>
			</div>
			<div id="box" class="row box-central">
						<div class="row">
							<div class="col-xs-6">
								<h1><?php echo $book_updbooking_title;?></h1>
							</div>
							<div class="col-xs-1">
								<div id="img-loading"></div>
							</div>
						</div>
						<form id="frm-booking-data">
							<div id="find-code" class="row margin-top-1em">
								<div class="col-xs-8 col-xs-offset-2">
									<label for="inputCode" class="control-label label-custom label-code"><?php echo $book_updbooking_find_code.':';?></label>
									<input id="inputCode" type="text" maxlength="6" class="input-code">
									<button id="btn-finbooking" type="button" class="btn"><img src="../img/icons/glyphicons_027_search.png"></button>	
								</div>
							</div>
							<div id="booking-data" class="row" style="display: none;">
								<div class="box-border-right col-xs-8">
									<div id="updPrice" class="row margin-top-1em">
										<div class="form-group">
											<label for="inputCheckIn" class="col-xs-2 control-label label-custom"><?php echo $book_check_in;?></label>
											<div class="col-xs-3">
												<input id="checkin" type="text">
											</div>
											<label for="inputCheckOut" class="col-xs-1 control-label label-custom"><?php echo $book_check_out;?></label>
											<div class="col-xs-3">
												<input id="checkout" type="text" id="checkout">
											</div>
											<div class="col-xs-3"><label class="control-label label-custom"><?php echo $book_guests;?></label>
												<?php selectGuests();?>
											</div>
										</div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputName" class="col-xs-2 control-label label-custom"><?php echo $book_data_name.' *';?></label>
										    <div class="col-xs-4">
										    	<input type="text" class="form-control" id="inputName" placeholder="<?php echo $book_data_name_h;?>" tabindex="1">
										    </div>
											<label for="inputLastName" class="col-xs-2 control-label label-custom"><?php echo $book_data_last_name.' *';?></label>
										    <div class="col-xs-4">
										    	<input type="text" class="form-control" id="inputLastName" placeholder="<?php echo $book_data_last_name_h;?>" tabindex="2">
										    </div>
										</div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputCountry" class="col-xs-2 control-label label-custom"><?php echo $book_data_country.' *';?></label>
										    <div class="col-xs-10">
										    	<div id="SelectCountry">
										    	</div>
										    </div>
									  </div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputEmail" class="col-xs-2 control-label label-custom"><?php echo $book_data_email.' *';?></label>
										    <div class="col-xs-4">
												<input id="inputEmail" type="email" class="form-control" placeholder="<?php echo $book_data_email_h;?>"  tabindex="4">
										    </div>
										    <label for="inputPhone" class="col-xs-2 control-label label-custom"><?php echo $book_data_phone.' *';?></label>
										    <div class="col-xs-4">
										    	<div class="input-group">
													<span id="dialingCode" class="input-group-addon"></span>
												  	<input id="inputPhone" type="text" class="form-control" placeholder="<?php echo $book_data_phone_h;?>" tabindex="6">
												</div>
										    </div>
									  	</div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputConfirmEmail" onpaste="return false" class="col-xs-2 control-label label-custom"><?php echo $book_data_conf_email.' *';?></label>
										    <div class="col-xs-4">
												<input id="inputConfirmEmail" type="email" class="form-control" placeholder="<?php echo $book_data_conf_email_h;?>" tabindex="5">
										    </div>
										    <label for="inputOptPhone" class="col-xs-2 control-label label-custom"><?php echo $book_data_opt_phone;?></label>
										    <div class="col-xs-4">
										    	<div class="input-group">
												  <span id="dialingOptCode" class="input-group-addon"></span>
												  <input id="inputOptPhone" type="text" class="form-control" placeholder="<?php echo $book_data_opt_phone_h;?>" tabindex="7">
												</div>
										    </div>
									  	</div>
									</div>
									<div class="row margin-top-1em">
										<div class="row">
											<div class="form-group">
												<label for="inputArrive" class="col-xs-4 col-xs-offset-1 control-label label-custom"><?php echo $book_data_arrive;?></label>
											    <div class="col-xs-4">
											    	<div id="SelectArrive">
												   	</div>
											    </div>
											</div>
										</div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputRequest" class="col-xs-2 control-label label-custom"><?php echo $book_data_request;?></label>
										    <div class="col-xs-10">
										    	<textarea class="form-control" id="inputRequest" placeholder="<?php echo $book_data_request_h;?>" tabindex="9"></textarea>
										    </div>
									  </div>
									</div>
								</div>
								<div class="col-xs-4">
									<div id="SelectCurrency">
									</div>
									<div class="row margin-top-1em">
										<div class="col-xs-10 col-xs-offset-1">
											<div id="pricing" class="box-no-border">
												<div class="row"><h3><?php echo $book_confirm_price;?></h3></div>
												<div class="row"><div class="col-xs-5 left no-padding"><p class="rates-guest"><?php echo $book_confirm_total_price;?></p></div><div class="col-xs-7 right no-padding"><p id="price" class="rates-guest right"></p></div></div>
												<div class="row"><div class="col-xs-5 left no-padding"><p class="rates-guest"><?php echo $book_confirm_iva;?></p></div><div class="col-xs-7 right no-padding"><p id="vat" class="rates-guest right"></p></div></div>
												<div class="row"><div class="col-xs-5 col-xs-offset-7 no-padding" style="height: 1.1em "><hr></div></div>
												<div class="row"><div class="col-xs-5 left no-padding"><p class="rates-guest"><?php echo $book_confirm_total;?></p></div><div class="col-xs-7 right no-padding"><p id="total" class="rates-guest right"></p></div></div>
											</div>
										</div>
									</div>
									<div class="row">
										<p class="rates-note">
											<img src="../img/info.png" class="img-info"/><?php echo $book_updbooking_msg_price_change;?>
										</p>
									</div>
									<div class="row">
										<div class="col-xs-6">
											<button id="btn-confirm" type="button" class="btn btn-success btn-custom"><?php echo $book_updbooking_confirm;?></button>
										</div>
										<div class="col-xs-6">
											<button id="btn-cancel" type="button" class="btn btn-danger btn-custom" data-toggle="modal" data-target="#modalCancel"><?php echo $book_updbooking_cancel;?></button>
										</div>
									</div>
								</div>
								<input type="hidden" id="code"/>
							</div>
							<!-- Modal: Cancelacion -->
							<div id="modalCancel" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
								<div class="modal-dialog modal-sm modal-dialog-alert">
							    	<div class="modal-content modal-content-alert">
							      		<div class="modal-header modal-header-alert">
							        		<h2 class="modal-title" id="lblSrv"><?php echo $book_updbooking_cancel;?></h2>
							       		</div>
							      		<div class="modal-body modal-body-alert">
							      			<p><?php echo $book_updbooking_cancel_text;?></p>
										</div>
										<div class="modal-footer modal-footer-alert">
									    	<button id="btn-cancel-yes" type="button" class="btn btn-danger btn-custom"><?php echo $book_updbooking_cancel_yes;?></button>
									        <button type="button" class="btn btn-info btn-custom" data-dismiss="modal"><?php echo $book_updbooking_cancel_no;?></button>
									    </div>
							      	</div>
							    </div>
							</div>
							<script type="text/javascript">
								$('#btn-cancel-yes').on('click',function(e){
									g("../ajax.php?"+a('cancelBooking')+v('code'), 'result' , 'div-msg' , 'img-loading',false);
									$('#modalCancel').modal('hide');
								});
							</script>
						</form>
						<div id="div-msg" style="display: none"></div>
						<div id="confirmation1" style="display: none"></div>
						<div id="confirmation2" style="display: none"></div>
						<div id="result"></div>	

			</div>
		</div>
		
		<div id="footer">
			<?php include("footer.php");?>
		</div>
	</body>
</html>